<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use DB;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function Login()
    {
        //echo '这里是后台登陆页面';
        return view('Admin.Login.Login');
    }

    public function doLogin(Request $request)
    {
        // echo '登陆成功';
        // dd($request->all());

        //获取用户密码
        $username=$request->input('username');
        $password=$request->input('password');
        //dd($username,$password);

        $result=DB::table('users')
        ->whereIn('aid',[2,3,4,5])
        ->where('username',$username)
        ->where('password',$password)
        ->first();
        if($result){
            //存入cookie
            //return response()->view()->withCookie(['username',10,10],['aid',5,5]);
            return redirect('/admin/index')->withCookie(['username',10,10]);

            //跳转后台首页
        }else{
            //返回 响应存入闪存
            // redirect();
            // return redirect('admin/login')->withInput();
            return back()->withInput();
        }
    }
}
